package com.acwing.partition7;

import java.io.*;

/**
 * @author rkc
 * @date 2022/7/15 9:11
 */
public class AC691立方体IV {

    private static final int N = 1010;
    private static final int[][] dirs = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
    private static int[][] g = new int[N][N], f = new int[N][N];
    private static int n;

    private static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    private static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        int t = nextInt();
        for (int k = 0; k < t; k++) {
            reset();
            n = nextInt();
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    g[i][j] = nextInt();
                }
            }
            int step = 0, start = n * n;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    int res = dfs(i, j);
                    if (res == step) start = Math.min(start, g[i][j]);
                    else if (res > step) {
                        step = res;
                        start = g[i][j];
                    }
                }
            }
            writer.format("Case #%d: %d %d\n", k + 1, start, step);
        }
        writer.flush();
    }

    private static int dfs(int x, int y) {
        if (f[x][y] != 1) return f[x][y];
        for (int[] dir : dirs) {
            int nx = dir[0] + x, ny = dir[1] + y;
            if (nx < 0 || ny < 0 || nx >= n || ny >= n || g[x][y] + 1 != g[nx][ny]) continue;
            f[x][y] = Math.max(f[x][y], dfs(nx, ny) + 1);
        }
        return f[x][y];
    }

    private static void reset() {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                g[i][j] = 0;
                f[i][j] = 1;
            }
        }
        n = 0;
    }

    private static int nextInt() throws IOException {
        tokenizer.nextToken();
        return (int) tokenizer.nval;
    }
}
